﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Globalization;
using System.IO;
namespace PayPalApp
{
    class PayPal
    {
        DateTime start;
        DateTime end;
        String BankAccount;
        DataHelper dh;

        public PayPal()
        {
            dh = new DataHelper();
        }

        public int readFromFile(String filename)
        {
            FileStream fs = null;
            StreamReader sr = null;
            try
            {
                fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
                sr = new StreamReader(fs);
               // s = sr.ReadLine();
                BankAccount = sr.ReadLine();
                //start = Convert.ToDateTime(sr.ReadLine());
                start = DateTime.ParseExact(sr.ReadLine(), "yyyy/MM/dd/HH:mm:ss", CultureInfo.InvariantCulture);
               // end = Convert.ToDateTime(sr.ReadLine());
                end = DateTime.ParseExact(sr.ReadLine(), "yyyy/MM/dd/HH:mm:ss", CultureInfo.InvariantCulture);
                int nr = Convert.ToInt32(sr.ReadLine());
                String s;
                for (int i = 1; i <= nr; i++)
                {
                    s = sr.ReadLine();
                    string[] arr = s.Split(' ');
                    String account = arr[0];
                    Double amount = Convert.ToDouble(arr[1]);
                    if (dh.updateAccount(account, amount) != -1)
                    {
                        return 1;
                    }
                }
                return - 1;
            }
            catch (IOException)
            {
                return -1;
            }
            finally
            {
                if (sr != null) sr.Close();
                if (fs != null) fs.Close();
            }
        }

    }
}
